<template>
  <a-modal 
        :visible="visible"
        okText="确定" 
        cancelText="取消"
        :title="title"
        :maskClosable="false"
        :destroyOnClose="true"
        :keyboard="false"
        :closable="false"
        width="400px"
        @cancel="closeModal()" 
        @ok="handleSubmit">
        <a-form-model :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }"
            :model="formData" 
            :rules="rules"
            ref="ruleForm">
            <p style="margin-bottom: 10px; font-size: 14px; color: red">批量设置秒杀库存价格后，请点击保存按钮。</p>
            <a-form-model-item label="秒杀库存数量" prop="seckillStock">
                <a-input-number style="width:200px;" v-model="formData.seckillStock" :precision="0" :min="maxOrderCount || 1" :max="minGoodsInventory"/>
            </a-form-model-item>
            <a-form-model-item label="秒杀价格" prop="seckillPrice">
                <a-input-number style="width:200px;" v-model="formData.seckillPrice" :precision="2" :min="0.1" :max="minSalePrice"/>
            </a-form-model-item>
        </a-form-model>
  </a-modal>
</template>

<script>
export default {
    props: {
        visible:{
            type:Boolean,
            default:false,
        },
        minGoodsInventory:{
            type:Number,
            default: 1,
        },
        minSalePrice:{
            type:Number,
            default: 0.1,
        },
        maxOrderCount:{
            type:Number,
            default: 0,
        },
    },
    data(){
        return {
            title:'批量设置秒杀库存价格',
            formData:{
                seckillStock: 0,
                seckillPrice:'',
            },
            rules:{
                seckillStock: [{ required:true, message:'请输入秒杀库存数量'}],
                seckillPrice: [{ required:true, message:'请输入秒杀价格'}],
            }
        }
    },
    methods:{
        closeModal (freshTable) {
            this.$emit('cancel', freshTable)
        },
        handleSubmit(){
            this.$refs.ruleForm.validate(valid=>{
                console.log('valid',valid);
                if(valid){
                    console.log('this.formData',this.formData);
                    this.$emit('submit',this.formData);
                }
            });
        }
    }
}
</script>

<style lang="less" scoped>

</style>